//
//  ResetPasswordController.m
//  TCProject
//
//  Created by admin on 16/1/25.
//  Copyright © 2016年 wise-wing. All rights reserved.
//

#import "ResetPasswordController.h"
#import "User.h"
#import "AccountManager.h"

@interface ResetPasswordController ()

@property (weak, nonatomic) IBOutlet UITextField *textField1;
@property (weak, nonatomic) IBOutlet UITextField *textField2;

- (IBAction)okSender:(id)sender;

@end

@implementation ResetPasswordController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (_type) {
        self.title = @"设置密码";
    } else {
        self.title = @"重置密码 ";
    }

}





- (IBAction)okSender:(id)sender {
    NSString *password1 = _textField1.text;
    NSString *password2 = _textField2.text;
    if (password1.length < 6 || password1.length > 16) {
        [self showHint:@"请输入6-16位密码!"];
        return;
    }
    if (![password1 isEqualToString:password2]) {
        [self showHint:@"两次输入不一致"];
        return;
    }
    
    BMRequest *request;
    if (_type) {
        request = [BMRequest requestWithPath:@"register.htm" contentKey:kRoleType ? @"Dispatcher" : @"Owner"];
        request.params = @{@"mobile": _mobile, @"password": password1, @"role": kRole};
    } else {
        request = [BMRequest requestWithPath:@"findBackPassword.htm"];
        request.params = @{@"mobile": _mobile, @"newPassword": password1, @"role": kRole};
    }
    
    weakSelf(self);
    [self showHudWithhint:kDefaultMessage];
    [User postWithRequest:request finish:^(BMResponse *response, NSError *error) {
        [self hideHud];
        if (response.status == kResultOK) {
            if (_type) {
                [AccountManager sharedInstance].user = response.result;
                [weakSelf dismissViewControllerAnimated:YES completion:nil];
            } else {
               // [[AccountManager sharedInstance] logout];  //极光推送内容
                [weakSelf.navigationController popToRootViewControllerAnimated:YES];
            }
        } else {
            [self showHint:response.msg];
        }
    }];


}
    
    
@end
